﻿using System;

namespace _1___LinkedList {
    public class Node<T> {
        public Node<T> Next { get; set; }
        public T Data { get; set; }

        public Node(T t) {
            Next = null;
            Data = t;
        }
    }
    public class GenericList<T> {
        private Node<T> head;
        private Node<T> tail;

        public GenericList() {
            tail = head = null;
        }
        public Node<T> Head {
            get => head;
        }
        public void Add(T t) {
            Node<T> n = new Node<T>(t);
            if (tail == null) {
                head = tail = n;
            }
            else {
                tail.Next = n;
                tail = n;
            }
        }
        public void ForEach(Action<T> action) {
            for (Node<T> node = head; node != null; node = node.Next) {
                action(node.Data);
            }
        }
    }
    class Program {
        static void Main(string[] args) {
            int maxNum = int.MinValue,
                minNum = int.MaxValue,
                sum = 0;
            Action<int> print = num => Console.WriteLine(num);
            Action<int> getMax = num => maxNum = (num > maxNum) ? num : maxNum;
            Action<int> getMin = num => minNum = (num < minNum) ? num : minNum;
            Action<int> getSum = num => sum += num;

            GenericList<int> intList = new GenericList<int>();
            for (int x = 0; x < 10; x++) {
                intList.Add(x);
            }

            Console.WriteLine("Elements:");
            intList.ForEach(print);
            Console.WriteLine("Max Num:");
            intList.ForEach(getMax);
            Console.WriteLine(maxNum);
            Console.WriteLine("Min Num:");
            intList.ForEach(getMin);
            Console.WriteLine(minNum);
            Console.WriteLine("Sum:");
            intList.ForEach(getSum);
            Console.WriteLine(sum);
        }
    }
}
